<?php require_once('Connections/online.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "frm")) {
  $updateSQL = sprintf("UPDATE categoria SET nombre=%s WHERE id_categoria=%s",
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['id_categoria'], "int"));

  mysql_select_db($database_online, $online);
  $Result1 = mysql_query($updateSQL, $online) or die(mysql_error());

  $updateGoTo = "modificar_categorias.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
?>

<?php
include("conexion.php");
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Categoria</title>
    <link rel="stylesheet" href="jquery.ui.all.css">
<link rel="stylesheet" href="demos.css">
<link rel="stylesheet" href="jquery.ui.datepicker.css">
<link rel="stylesheet" href="css/jquery-ui-1.8.20.custom.css">
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.8.20.custom.min.js"></script>
<script src="ui/jquery.ui.core.js"></script>
	<script src="ui/jquery.ui.widget.js"></script>
	<script src="ui/jquery.ui.datepicker.js"></script>
	<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script>
	$(function() {
		$( "#calendario" ).datepicker();
	});
	</script>
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
    <style type="text/css">
<!--
.Estilo1 {color: #000080}
.Estilo2 {
	font-size: 36px;
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-weight: bold;
}
-->
    </style>
    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Header -->
<div id="header">
	<div class="shell">
		<!-- Logo + Top Nav -->
		<div id="top">
			<h1><a href="#">	<span class="Estilo2">Veterinaria</span> Peluvets</a></h1>
<div id="top-navigation">
				 <a href="index.php"><strong>Cerrar</strong></a>
			
			</div>
		</div>
		<!-- End Logo + Top Nav -->
		
		<!-- Main Nav -->
	<div id="navigation">
		<ul id="nav">
			    <li><a href="categorias.php" ><span>Categoria</span></a>
                 <ul id="navi">
          
</li>
      </ul>
	            <li><a href="usuarios.php"><span>Usuarios</span></a></li>
				<li><a href="productos.php"><span>Productos</span></a></li>
				 
				
			</ul>
		</div>
	  <!-- End Main Nav -->
	</div>
</div>

<div id="container">
<div class="shell">
		
		<!-- Small Nav -->
		<div class="small-nav"></div>
		<!-- End Small Nav -->
		
		<!-- Message OK -->
	  <!-- End Message OK -->		
		
	  <!-- Message Error -->
	  <!-- End Message Error -->
  <br />
		<!-- Main -->
		<div id="main">
			<div class="cl"></div>
			
			<div id="manten">
				
				<!-- Box -->
				<div class="box">
					<!-- Box Head -->
					<div class="box-head">
                      <h2 class="left">Modificar Categorias&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </h2>
                      <div class="right"> <a href="categorias.php">
                        <input type="submit" class="button" value="Eliminar" />
                      </a> </div>
				  </div>
					<!-- End Box Head -->	
                     
                     
 <?php
 
include "conexion.php";

 
$query="SELECT * FROM categoria ";
 
$result=mysql_query($query) or die("Error: ".mysql_error());
  
if(mysql_num_rows($result) > 0){
 
?>
                     <div class="table">
                     <table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
							  <th width="253"><div align="left">Codigo</div></th>
							  <th width="172"><div align="left">Categoria</div></th>
                              <th width="223" class="ac"><div align="left">Modificar</div></th>
						  </tr>
<?php    
 
  while($Rs=mysql_fetch_array($result)) { 
      echo "<tr>".
      "<tr><td>".$Rs["id_categoria"]."</td>".
	  "<td>".$Rs["nombre"]."</td>".
      "<td><a href=./modificar_categorias.php?id_categoria=".$Rs["id_categoria"]." class='ico del'>Modificar</a></td>".
    "</tr>";
				  
}
 
}else{
 
echo "No hay categorias registradas para listar";
 
}
 
?>
                     
    </table> 

    
      
    </div>    
                     
                     
           
						</table>
                        
                        
						<!-- Pagging -->
						
			  </div>
	  </div>
	</div>
        		<!-- Pagging -->
						
		  </div>
	  </div>
        
        
</div>
</div>
<div id="fin">
	<div class="shell">
		
        
            
    <div id="sidebar">
				
				<!-- Box -->
				<div class="box">
				
					
					<div class="box-content">
    
    
           <?php
 
include "conexion.php";

 
if(isset($_POST["submit"])){
 
    $query = "UPDATE categoria SET nombre='".$_POST["nombre"]."', ".
        "id_marca='".$_POST["id_categoria"]."' WHERE id_categoria=".$_POST["id_categoria"];
    mysql_query($query) or die("Error: ".mysql_error());
    echo "Id.$id_categoria ha sido modificado<br>";
 
}else{

 
    $id_categoria=$_GET['id_categoria'];
    $query="SELECT * FROM categoria WHERE id_categoria='".$id_categoria."'";
    $result=mysql_query($query) or die("Error: ".mysql_error());

 
    if(mysql_num_rows($result) > 0){
 
    while($Rs=mysql_fetch_array($result)) {
 
    ?>
 <div class="table">
    <form  method=POST name=frm action="<?php echo $editFormAction; ?>">
        <table width="307">
       <tr><th colspan="2"><span class="Estilo1"><h3 align="center">Modificar Registro</h3></span></th>
       </tr>
	    <tr>
        <td class="Estilo23 Estilo1">Codigo</td>
        <td><span id="sprytextfield2">
          <input name='id_categoria'  type='text' maxlength='50' value="<?php echo $Rs['id_categoria']; ?>" readonly='true'>
          </span></td>
        </tr>
      <tr>
        <td width="86" class="Estilo23 Estilo1">Categoria</td>
        <td width="209"><span id="sprytextfield1">
          <input name='nombre'  type='text' maxlength='20' value="<?php echo $Rs['nombre']; ?>">
         </span></td>
        </tr>
     
      
      <tr>
        <td>&nbsp;</td>
        <td><input name='submit' class="button" type='submit' value='Enviar'></td>
      </tr>
    </table>
        <input type="hidden" name="MM_update" value="frm">
    </form>
 
    <?php
    }
 
    }else{
        echo "No fué posible realizar la operación solicitada ".$id_categoria;
    }
}

 
?>
 
</table>
</form>
        
        
	</div>
</div>
	
                                        <script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
//-->
</script>
</body>
</html>